use regex::Regex;
use lazy_static::lazy_static;

lazy_static! {
    ///0 pub fn 1 fn_name 2 (...) 3 return 4 any to end
    static ref RE_FN: Regex = Regex::new(r"(.*\bfn\b )(\w+)(\(.*\)) (\w*)\n([^]*\n)").unwrap();
}

pub fn domain(s: &str) -> String {
    let head = format!("// generate by pr language\n// original code :\n\n/*\n{}\n*/\n", s);
    let code = parse(s);
    format!("{}{}", head, code)
}

fn parse(s: &str) -> String {
    parse_fn(s)
}

fn parse_fn(s: &str) -> String {
    let fn_code = String::new();
    for captures in RE_FN.captures_iter(s) {
        println!("captures: {:?}", captures);
        captures.get()
    }
    s.to_string()
}

fn blank_to_colon(s: &str) -> String {
    let mut param = String::new();
    let sp = s.split(",");
    for ss in sp {
        let tmp = ss.trim().replace(" ", ":");
        param.push_str(&tmp);
        param.push(',');
    }
    param.remove(param.len());
    param
}

#[test]
fn test(){

}